%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This MATLAB code generates all theory based graphs and all results from 
% the Online Appendix of the paper "Process or Candidate: The International
% Community and the Demand for Electoral Integrity". 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Preliminaries

clear all;

co = [0 0 1;
      0 0.5 0;
      1 0 0;
      0 0.75 0.75;
      0.75 0 0.75;
      0.75 0.75 0;
      0.25 0.25 0.25]; %this gives rgb triplets for standard colors

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Scenario of Election Hegemon
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Solving the FOCS using the symbolic toolbx

% Set symbolic parameters
syms pi Gamma Lambda chi b p c ; 

%Formula of government vote share
x_gov = chi + c + (sqrt(b)-p).*(sqrt(b)-c);

%Formula of resulting bias
beta_p = b-sqrt(b).*p;

%Utility of the international power
u_int = Gamma.*pi.*x_gov - Lambda.*beta_p - c.^2 - p.^2;

%2 FOCS

dc_u_int = diff(u_int,c);
dp_u_int = diff(u_int,p);

% Compute Hessian

dcc_u_int = diff(dc_u_int,c)
dcp_u_int = diff(dc_u_int,p)
dpp_u_int = diff(dp_u_int,p)
dpc_u_int = diff(dp_u_int,c) %symmetry (!)

%Solve the FOCS

S = solve(dc_u_int==0,dp_u_int==0,c,p);

%Compute other outcomes
S.x_gov = chi + S.c + (sqrt(b)-S.p).*(sqrt(b)-S.c);
S.beta_p = b-sqrt(b).*S.p;

%Create a Matlab function from the solution of the FOCs and include
%outcomes
eq_electoral_hegemon = matlabFunction(S.c,S.p,S.x_gov,S.beta_p,'Vars', [pi Gamma Lambda chi b]);

%Initialize baseline scenario

chi     =.5  %incumbent vote share
b       =.15 %initial bias
Gamma   =.75 %importance of country
Lambda  =.5  %importance of liberalism

%Create pi_n-Vector for the x-axis of the plots
pi_low  = -.5;   %lowest value on x-axis
pi_high = .5;     %highest value on x axis
n       = 1001;   %how many points are used for computation of y-values
pi_n    = linspace(pi_low,pi_high,n); %grid for pi

%Create values1
[cstar1,pstar1,gvtshare1,bias1] = eq_electoral_hegemon(pi_n, Gamma, Lambda, chi, b);

u_nonstrategic_baseline = Gamma.*pi_n.*gvtshare1-Lambda.*(b-sqrt(b).*(pstar1))-cstar1.^2-pstar1.^2;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Scenario of Election War
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Solving the FOCS using the symbolic toolbx
% The following part derives the FOCs, and does some rearranging

syms pi Gammaplus Gammaminus Lambdaplus Lambdaminus b pplus pminus cplus cminus chi

voteshare = chi + cplus +cminus + (sqrt(b)-(pplus+pminus))*(sqrt(b)-cplus-cminus)

uplus = Gammaplus*pi*voteshare-Lambdaplus*(b-sqrt(b)*(pplus+pminus))-cplus^2-pplus^2
uminus = -Gammaminus*pi*voteshare-Lambdaminus*(b-sqrt(b)*(pplus+pminus))-cminus^2-pminus^2

%%%%

dpuplus = diff(uplus,pplus)
dcuplus = diff(uplus,cplus)

%%%%

dpuminus = diff(uminus,pminus)
dcuminus = diff(uminus,cminus)


% General Case: Solve the system of 4 equations in 4 variables and save
% solution in Matlab function. Create a system of algebraic equations from 
% first order conditions

S = solve(dpuplus==0,dcuplus==0, dpuminus==0,dcuminus==0,cplus,cminus,pplus,pminus)

equilibrium = matlabFunction([S.cplus S.cminus S.pplus S.pminus],'Vars', {[chi b Gammaplus Lambdaplus Gammaminus Lambdaminus pi]})

% 1 - SYMMETRIC PARAMETRIZATION

n=1001

chi=.5 %incumbent vote share
b =0.15 %initial bias
Gammaplus=.75  %importance of country for '+'-power
Lambdaplus=.5 %importance of liberalism for '+'-power
Gammaminus=.75  %importance of country for '-'-power
Lambdaminus=.5 %importance of liberalism for '-'-power

%generate a vector of input arguments (the parameter vector) for functions
parameters = [chi b Gammaplus Lambdaplus Gammaminus Lambdaminus pi]

% 1 - SYMMETRIC PARAMETRIZATION - SOLUTION

%intialize vectors of optima
cplusstar = ones(1,n);
cminusstar = ones(1,n);
pplusstar = ones(1,n);
pminusstar = ones(1,n);

%Compute equilibrium for each value of pi
for n = 1:n
    pivalue = pi_n(n);
    parameters = [chi b Gammaplus Lambdaplus Gammaminus Lambdaminus pivalue];
    equilibriumvector = equilibrium(parameters)
    cplusstar(n) = equilibriumvector(:,1);
    cminusstar(n) = equilibriumvector(:,2);
    pplusstar(n) = equilibriumvector(:,3);
    pminusstar(n) = equilibriumvector(:,4);
end

%compute other outcomes
voteshare = chi + cplusstar +cminusstar + (sqrt(b)-(pplusstar+pminusstar)).*(sqrt(b)-cplusstar-cminusstar);
expenditures = [cplusstar.^2+pplusstar.^2; cminusstar.^2+pminusstar.^2];

%save for a comparison with the hegemon case

cplusstar_strategic_symmetric = cplusstar;
pplusstar_strategic_symmetric = pplusstar;
gvtshare_strategic_symmetric = voteshare;
expenditure_strategic_symmetric = cplusstar.^2+pplusstar.^2;
expenditure_strategic_symmetric_minuspower = cminusstar.^2+pminusstar.^2;
bias_strategic_symmetric = b-sqrt(b).*(pplusstar+pminusstar);
uplus_strategic_symmetric = Gammaplus.*pi_n.*voteshare-Lambdaplus.*(b-sqrt(b).*(pplusstar+pminusstar))-cplusstar.^2-pplusstar.^2;
uminus_strategic_symmetric = -Gammaminus.*pi_n.*voteshare-Lambdaminus.*(b-sqrt(b).*(pplusstar+pminusstar))-(cminusstar.^2+pminusstar.^2);

n=1001

chi=.5 %incumbent vote share
b =0.15 %initial bias
Gammaplus=.75  %importance of country for '+'-power
Lambdaplus=.5 %importance of liberalism for '+'-power
Gammaminus=.0  %importance of country for '-'-power/Int. Organization
Lambdaminus=.5 %importance of liberalism for '-'-power/Int. Organization

%generate a vector of input arguments (the parameter vector) for functions
parameters = [chi b Gammaplus Lambdaplus Gammaminus Lambdaminus pi]

%Create an x-axis for plots
pi_n = linspace(-0.5,0.5,n);

% 1 - Int. Organization - SOLUTION

%intialize vectors of optima
cplusstar = ones(1,n);
cminusstar = ones(1,n);
pplusstar = ones(1,n);
pminusstar = ones(1,n);

%Compute equilibrium for each value of pi
for n = 1:n
    pivalue = pi_n(n);
    parameters = [chi b Gammaplus Lambdaplus Gammaminus Lambdaminus pivalue];
    equilibriumvector = equilibrium(parameters)
    cplusstar(n) = equilibriumvector(:,1);
    cminusstar(n) = equilibriumvector(:,2);
    pplusstar(n) = equilibriumvector(:,3);
    pminusstar(n) = equilibriumvector(:,4);
end

%compute other outcomes
voteshare = chi + cplusstar +cminusstar + (sqrt(b)-(pplusstar+pminusstar)).*(sqrt(b)-cplusstar-cminusstar);
expenditures = [cplusstar.^2+pplusstar.^2; cminusstar.^2+pminusstar.^2];

%save in file for a comparison 
cplusstar_strategic_internationalorganization = cplusstar;
pplusstar_strategic_internationalorganization = pplusstar;
gvtshare_strategic_internationalorganization = voteshare;
expenditure_strategic_internationalorganization = cplusstar.^2+pplusstar.^2;
expenditure_strategic_internationalorganization_minuspower = cminusstar.^2+pminusstar.^2;
bias_strategic_internationalorganization = b-sqrt(b).*(pplusstar+pminusstar);
uplus_strategic_internationalorganization = Gammaplus.*pi_n.*voteshare-Lambdaplus.*(b-sqrt(b).*(pplusstar+pminusstar))-cplusstar.^2-pplusstar.^2;
uminus_strategic_internationalorganization = -Gammaminus.*pi_n.*voteshare-Lambdaminus.*(b-sqrt(b).*(pplusstar+pminusstar))-(cminusstar.^2+pminusstar.^2);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Figure 11: Equilibrium Choices with International Organization
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% COMPARISON PLOT OF INVESTMENT c-* and c+* %%%

plot(pi_n,cplusstar,'b',pi_n,cminusstar,'--b')
set(gca,'YLim',[-0.2 0.2])
line('XData', [0 0] , 'YData', [-0.2 0.2] , 'LineStyle', ':', 'LineWidth', 1, 'Color','r') %vertical line for pi=0
legend({'$$c_+^*$$ (Foreign Power)','$$c_-^*$$ (Int. Organization)'},'Location','southeast','Interpreter','latex')
xlabel({'Polarization $$\pi$$'},'Interpreter','latex')
ylabel({'Optimal Values $$c_+^*,c_-^*$$'},'Interpreter','latex')

%Save plot
saveas(gcf,'matlab_online_appendix/figure11a.png')

%%% COMPARISON PLOT OF INVESTMENT p-* and p+* %%%

h1=plot(pi_n,pplusstar,'Color',co(2,:))
h2=line(pi_n,pminusstar,'LineStyle','--','Color',co(2,:))
set(gca,'YLim',[-0.2 0.2])
line('XData', [0 0] , 'YData', [-0.2 0.2] , 'LineStyle', ':', 'LineWidth', 1, 'Color','r') %vertical line for pi=0
legend({'$$p_+^*$$ (Foreign Power)','$$p_-^*$$ (Int. Organization)'},'Location','southeast','Interpreter','latex')
xlabel({'Polarization $$\pi$$'},'Interpreter','latex')
ylabel({'Optimal Values $$p_+^*,p_-^*$$'},'Interpreter','latex')

%Save plot
saveas(gcf,'matlab_online_appendix/figure11b.png')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Figure 12: Outcomes with International Organization
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% COMPARISON PLOT OF VOTE SHARES  - HEGEMON VS. INTERNATIONAL ORGANIZATION %%%

plot(pi_n,gvtshare1,'k',pi_n,gvtshare_strategic_internationalorganization,'--k')
hold on
plot(-.5,.65,'<','MarkerSize',10,'MarkerEdgeColor',[0.2 0.2 0.2],'MarkerFaceColor',[0.9  0.75 0])
hold off
set(gca,'YLim',[0 1]) 
legend({'Election Hegemon','Entry of Int. Organization','SQ'},'Location','southeast','Interpreter','latex')
xlabel({'Polarization $$\pi$$'},'Interpreter','latex')
ylabel('Final Vote Share $$f$$','Interpreter','latex')

%Save plot
saveas(gcf,'matlab_online_appendix/figure12a.png')

%%% COMPARISON PLOT OF BIAS  - HEGEMON VS. INTERNATIONAL ORGANIZATION %%%

plot(pi_n,bias1,'k',pi_n,bias_strategic_internationalorganization,'--k')
hold on
plot(-.5,.15,'<','MarkerSize',10,'MarkerEdgeColor',[0.2 0.2 0.2],'MarkerFaceColor',[0.9  0.75 0])
hold off
set(gca,'YLim',[0 0.2]) 
legend({'Election Hegemon','Entry of Int. Organization','SQ'},'Location','northwest','Interpreter','latex')
xlabel({'Polarization $$\pi$$'},'Interpreter','latex')
ylabel('Resulting Bias $$\beta$$','Interpreter','latex')

%Save plot
saveas(gcf,'matlab_online_appendix/figure12b.png')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Figure 14: Expenditure on p with International Organization
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Plot the total expenditures of the international powers
plot(pi_n, pstar1.^2,'k', pi_n, pplusstar.^2,'--k',pi_n,pminusstar.^2,':k')
set(gca,'YLim',[0 0.05]) 
legend({'Election Hegemon','($$+$$) Foreign Power','($$-$$) Int. Organization'},'Location','northeast','Interpreter','latex')
xlabel({'Polarization $$\pi$$'},'Interpreter','latex')
ylabel('Expenditure $${p^*}^2$$','Interpreter','latex')

%Save plot
saveas(gcf,'matlab_online_appendix/figure14.png')

% 1 - Int. Organization PARAMETRIZATION 2

n=1001

chi=.5 %incumbent vote share
b =0.15 %initial bias
Gammaplus=.75  %importance of country for '+'-power
Lambdaplus=0 %importance of liberalism for '+'-power
Gammaminus=.0  %importance of country for '-'-power/Int. Organization
Lambdaminus=.5 %importance of liberalism for '-'-power/Int. Organization

%generate a vector of input arguments (the parameter vector) for functions
parameters = [chi b Gammaplus Lambdaplus Gammaminus Lambdaminus pi]

% 1 - Int. Organization - SOLUTION

%intialize vectors of optima
cplusstar = ones(1,n);
cminusstar = ones(1,n);
pplusstar = ones(1,n);
pminusstar = ones(1,n);

%Compute equilibrium for each value of pi
for n = 1:n
    pivalue = pi_n(n);
    parameters = [chi b Gammaplus Lambdaplus Gammaminus Lambdaminus pivalue];
    equilibriumvector = equilibrium(parameters)
    cplusstar(n) = equilibriumvector(:,1);
    cminusstar(n) = equilibriumvector(:,2);
    pplusstar(n) = equilibriumvector(:,3);
    pminusstar(n) = equilibriumvector(:,4);
end

%compute other outcomes
voteshare = chi + cplusstar +cminusstar + (sqrt(b)-(pplusstar+pminusstar)).*(sqrt(b)-cplusstar-cminusstar);
expenditures = [cplusstar.^2+pplusstar.^2; cminusstar.^2+pminusstar.^2];

%save in file for a comparison 
cplusstar_strategic_internationalorganization = cplusstar;
pplusstar_strategic_internationalorganization = pplusstar;
gvtshare_strategic_internationalorganization = voteshare;
expenditure_strategic_internationalorganization = cplusstar.^2+pplusstar.^2;
expenditure_strategic_internationalorganization_minuspower = cminusstar.^2+pminusstar.^2;
bias_strategic_internationalorganization = b-sqrt(b).*(pplusstar+pminusstar);
uplus_strategic_internationalorganization = Gammaplus.*pi_n.*voteshare-Lambdaplus.*(b-sqrt(b).*(pplusstar+pminusstar))-cplusstar.^2-pplusstar.^2;
uminus_strategic_internationalorganization = -Gammaminus.*pi_n.*voteshare-Lambdaminus.*(b-sqrt(b).*(pplusstar+pminusstar))-(cminusstar.^2+pminusstar.^2);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Figure 13: Equilibrium Choices with International Organization
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% COMPARISON PLOT OF INVESTMENT c-* and c+* %%%

plot(pi_n,cplusstar,'b',pi_n,cminusstar,'--b')
set(gca,'YLim',[-0.2 0.2])
line('XData', [0 0] , 'YData', [-0.2 0.2] , 'LineStyle', ':', 'LineWidth', 1, 'Color','r') %vertical line for pi=0
legend({'$$c_+^*$$ (Foreign Power)','$$c_-^*$$ (Int. Organization)'},'Location','southeast','Interpreter','latex')
xlabel({'Polarization $$\pi$$'},'Interpreter','latex')
ylabel({'Optimal Values $$c_+^*,c_-^*$$'},'Interpreter','latex')

%Save plot
saveas(gcf,'matlab_online_appendix/figure13a.png')

%%% COMPARISON PLOT OF INVESTMENT p-* and p+* %%%
h1=plot(pi_n,pplusstar,'Color',co(2,:))
h2=line(pi_n,pminusstar,'LineStyle','--','Color',co(2,:))
set(gca,'YLim',[-0.2 0.2])
line('XData', [0 0] , 'YData', [-0.2 0.2] , 'LineStyle', ':', 'LineWidth', 1, 'Color','r') %vertical line for pi=0
legend({'$$p_+^*$$ (Foreign Power)','$$p_-^*$$ (Int. Organization)'},'Location','southeast','Interpreter','latex')
xlabel({'Polarization $$\pi$$'},'Interpreter','latex')
ylabel({'Optimal Values $$p_+^*,p_-^*$$'},'Interpreter','latex')

%Save plot
saveas(gcf,'matlab_online_appendix/figure13b.png')

% 1 - PARAMETERS ILLIBERAL

chi=.5 %incumbent vote share
b =0.15 %initial bias
Gammaplus=.75  %importance of country for '+'-power
Lambdaplus=.5 %importance of liberalism for '+'-power
Gammaminus=1.0  %importance of country for '-'-power
Lambdaminus=0 %importance of liberalism for '-'-power %%ILLIBERAL%%

%generate a vector of input arguments (the parameter vector) for functions
parameters = [chi b Gammaplus Lambdaplus Gammaminus Lambdaminus pi]

% 1 - SOLUTION ILLIBERAL

%intialize vectors of optima
cplusstar = ones(1,n);
cminusstar = ones(1,n);
pplusstar = ones(1,n);
pminusstar = ones(1,n);

%Compute equilibrium for each value of pi
for n = 1:n
    pivalue = pi_n(n);
    parameters = [chi b Gammaplus Lambdaplus Gammaminus Lambdaminus pivalue];
    equilibriumvector = equilibrium(parameters)
    cplusstar(n) = equilibriumvector(:,1);
    cminusstar(n) = equilibriumvector(:,2);
    pplusstar(n) = equilibriumvector(:,3);
    pminusstar(n) = equilibriumvector(:,4);
end

%compute other outcomes
voteshare_illiberal = chi + cplusstar +cminusstar + (sqrt(b)-(pplusstar+pminusstar)).*(sqrt(b)-cplusstar-cminusstar);
bias_illiberal = b-sqrt(b)*(pplusstar+pminusstar);
uplus_strategic_illiberal = Gammaplus.*pi_n.*voteshare_illiberal-Lambdaplus.*(b-sqrt(b).*(pplusstar+pminusstar))-cplusstar.^2-pplusstar.^2;
uminus_strategic_illiberal = -Gammaminus.*pi_n.*voteshare-Lambdaminus.*(b-sqrt(b).*(pplusstar+pminusstar))-(cminusstar.^2+pminusstar.^2);
 
% 1 - PARAMETRIZATION ANTILIBERAL

chi=.5 %incumbent vote share
b =0.15 %initial bias
Gammaplus=.75  %importance of country for '+'-power
Lambdaplus=.5 %importance of liberalism for '+'-power
Gammaminus=1  %importance of country for '-'-power
Lambdaminus=-.5 %importance of liberalism for '-'-power %%ANTILIBERAL%%

%generate a vector of input arguments (the parameter vector) for functions
parameters = [chi b Gammaplus Lambdaplus Gammaminus Lambdaminus pi]

% 1 - SOLUTION ANTILIBERAL

%intialize vectors of optima
cplusstar = ones(1,n);
cminusstar = ones(1,n);
pplusstar = ones(1,n);
pminusstar = ones(1,n);

%Compute equilibrium for each value of pi
for n = 1:n
    pivalue = pi_n(n);
    parameters = [chi b Gammaplus Lambdaplus Gammaminus Lambdaminus pivalue];
    equilibriumvector = equilibrium(parameters)
    cplusstar(n) = equilibriumvector(:,1);
    cminusstar(n) = equilibriumvector(:,2);
    pplusstar(n) = equilibriumvector(:,3);
    pminusstar(n) = equilibriumvector(:,4);
end

%compute other outcomes
voteshare_antiliberal = chi + cplusstar +cminusstar + (sqrt(b)-(pplusstar+pminusstar)).*(sqrt(b)-cplusstar-cminusstar);
bias_antiliberal = b-sqrt(b)*(pplusstar+pminusstar);
uplus_strategic_antiliberal = Gammaplus.*pi_n.*voteshare_antiliberal-Lambdaplus.*(b-sqrt(b).*(pplusstar+pminusstar))-cplusstar.^2-pplusstar.^2;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Figure 15: Utility of Regime Overthrow vs. Baseline Scenarios
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%add the overthrowing utilities:

overthrow_govt = 0.75*pi_n-0.5-0.125
overthrow_opp = (0.75*0-0.5-0.125)*ones(1,n)

%%% Plot the utilities %%%
plot(pi_n, u_nonstrategic_baseline,'k', pi_n, uplus_strategic_symmetric,'--k',pi_n,overthrow_govt,':m',pi_n,overthrow_opp,':m')
set(gca,'YLim',[-1 1.25]) 
legend({'($$+$$) Power -- Hegemon','($$+$$) Power -- Election War', 'Regime Overthrow'},'Location','northwest','Interpreter','latex')
xlabel({'Polarization $$\pi$$'},'Interpreter','latex')
ylabel('Resulting Utility Level','Interpreter','latex')

%Save plot
saveas(gcf,'matlab_online_appendix/figure15a.png')

%add the overthrowing utilities:

overthrow_govt1 = -0.75*pi_n-0.5-0.125
overthrow_opp1 = (-0.75*0-0.5-0.125)*ones(1,n)

overthrow_govt2 = -0.5*pi_n-0-0.125
overthrow_opp2 = (-0.5*0-0-0.125)*ones(1,n)

%%% Plot the utilities %%%

plot(pi_n, uminus_strategic_symmetric,'k',pi_n,overthrow_govt1,'m:',pi_n, uminus_strategic_illiberal,'--k',pi_n,overthrow_govt2,'-.m',pi_n,overthrow_opp2,'-.m',pi_n,overthrow_opp1,'m:')
set(gca,'YLim',[-1 1.25]) 
legend({'($$-$$) Power -- Liberal','Overthrow -- Liberal','($$-$$) Power -- Aliberal','Overthrow -- Aliberal'},'Location','northeast','Interpreter','latex')
xlabel({'Polarization $$\pi$$'},'Interpreter','latex')
ylabel('Resulting Utility Level','Interpreter','latex')

%Save plot
saveas(gcf,'matlab_online_appendix/figure15b.png')

